﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataInfo;
using KenLib.BusinessManager;
using System.Collections.Generic;

// Coder: Thanh Dong 
// Date: 2012/04/06
// Status: Update

public partial class JOINT_frmJ_CompHistoryInput : System.Web.UI.Page
{

    本社情報Manager _本社情報Manager = new 本社情報Manager();
    本社履歴Manager _本社履歴Manager = new 本社履歴Manager();
    protected void Page_PreRender(object sender, EventArgs e)
    {
        ViewState["CountingSubmitJS59"] = Session["CountingSubmitJS59"];
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ((JOINT_MstPage_JOINT)this.Master).changeTitle("本社履歴情報登録");
        ((JOINT_MstPage_JOINT)this.Master).HideLiArea("frmJ_CompHistoryInput");

        if (Session["役"] == null || Session["役"].ToString() == "")
        {
            Response.Redirect("~/frmD_Login.aspx");
        }

        if (!IsPostBack)
        {
            ClearTextPage();
            LoadDataDropDownList_年度();
            Session["mode_frmJ_CompHistoryInput"] = "";
            Session["CountingSubmitJS59"] = Server.UrlEncode(System.DateTime.Now.ToString());
            ViewState["indexPage"] = 0;
            ddl_年度.Focus();
            
            /*-------------------This is Update mode----------------*/
            if (Request.QueryString["year"] != null)//Mode Update
            {
                int year;
                Int32.TryParse(Request.QueryString["year"].ToString(), out year);
                if (year != 0)
                {
                    // Session for go from page frmJ_JointCompBasicInfoRef
                    Session["frmJ_JointCompBasicInfoRef_Year"] = year;
                    Session["mode_frmJ_CompHistoryInput"] = "2";//Mode Update
                    int int_企業ID = Int32.Parse(Session["企業コード_2"].ToString());
                    DataTable dt = frmJ_CompHistoryInput_Select本社履歴With企業ID年度(int_企業ID, year);
                    if (dt.Rows.Count > 0)
                    {
                        LoadDataDropDownList_決算月(year.ToString());
                        string str_年度 = dt.Rows[0]["年度"].ToString();
                        if (str_年度 != "")
                        {
                            ListItem lst = ddl_年度.Items.FindByValue(str_年度);
                            ddl_年度.SelectedIndex = ddl_年度.Items.IndexOf(lst);
                        }
                        txt_売上.Text = dt.Rows[0]["売上"].ToString();
                        txt_営業損益.Text = dt.Rows[0]["営業損益"].ToString();
                        txt_経営損益.Text = dt.Rows[0]["経営損益"].ToString();
                        txt_当期損益.Text = dt.Rows[0]["当期損益"].ToString();

                        txt_常勤事務男.Text = dt.Rows[0]["常勤事務男"].ToString();
                        txt_常勤事務女.Text = dt.Rows[0]["常勤事務女"].ToString();
                        txt_常勤現場男.Text = dt.Rows[0]["常勤現場男"].ToString();
                        txt_常勤現場女.Text = dt.Rows[0]["常勤現場女"].ToString();
                        txt_非常勤事務男数.Text = dt.Rows[0]["非常勤事務男"].ToString();
                        txt_非常勤事務女数.Text = dt.Rows[0]["非常勤現場女"].ToString();
                        Session["frmJ_CompHistoryInput_ID"] = dt.Rows[0]["ID"].ToString();
                        string str_決算月 = dt.Rows[0]["決算月"].ToString();
                        if (dt.Rows[0]["決算月"].ToString() != "")
                        {
                            ListItem lst = ddl_決算月.Items.FindByValue(str_決算月);
                            ddl_決算月.SelectedIndex = ddl_決算月.Items.IndexOf(lst);
                        }
                        btn_登録.Text = "更新";
                        LoadDatainGridView(Int32.Parse(Session["企業コード_2"].ToString()));
                        
                        LoadErrorMessage();
                        btn_次.Enabled = true;
                    }
                    else
                    {
                        Response.Redirect("frmJ_JointCompBasicInfoRef.aspx");
                    }
                    
                }
                else
                {
                    Response.Redirect("frmJ_JointCompBasicInfoRef.aspx");
                }
            }
            else
            {
                ////////////////////////ELSE: Mode insert///////////////////////////////////////////////////
                ClearTextPage();
                LoadErrorMessage();
                LoadDatainGridView(Convert.ToInt32(Session["企業コード_2"]));
                Session["mode_frmJ_CompHistoryInput"] = "1";
                btn_次.Enabled = true;
                
                //Get Session["本社情報IdCurrent"] from JCompBasicCheck
                if (ViewState["EmtyData"] != null && ViewState["EmtyData"].ToString() == "2")
                {
                    btn_次.Enabled = true;
                }
                else
                {
                    AppCode_Common.ShowEmtyGrid<本社履歴>(grv, 4, "データがありません。", "");
                }

                // Because Sysadmin not role insert history 企業
                //string compcode = Session["本社情報IdCurrent"] != null ? Session["本社情報IdCurrent"].ToString() : "";
                //if (compcode != "")
                //{
                //    if (Session["役"] != null && Session["役"].ToString() == "2")
                //    {
                //        Session["mode_frmJ_CompHistoryInput"] = "3";
                //        //LoadDataGridViewWith企業ID(compcode);
                //        LoadDatainGridView(Convert.ToInt32(Session["企業コード_2"]));
                //    }
                //}
            }

        }
    }
   
    protected void btn_戻る_Click(object sender, EventArgs e)
    {
        if (Session["mode_frmJ_CompHistoryInput"].ToString() == "2" && Session["mode_frmJ_CompHistoryInput"] != null)
        {
            Response.Redirect("frmJ_JointCompBasicInfoRef.aspx");
        }
        else 
        {
            Response.Redirect("frmJ_CompBasicInputCheck.aspx");
        }
    }
    
    protected void btn_次_Click(object sender, EventArgs e)
    {
        //if (Session["mode_frmJ_CompHistoryInput"].ToString() == "2" && Session["mode_frmJ_CompHistoryInput"] != null)
        //{
        //    Response.Redirect("frmJ_CompBranchInput.aspx");
        //}
        //else
        //{
        //    Response.Redirect("frmJ_CompBranchInput.aspx");
        //}
        Response.Redirect("frmJ_CompBranchInput.aspx");
    }
    
    protected void btn_登録_Click(object sender, EventArgs e)
    {
        try
        {
            // Check mode insert or update
            if (Session["mode_frmJ_CompHistoryInput"] != null && Session["mode_frmJ_CompHistoryInput"].ToString() != "")
            {
                if (Session["CountingSubmitJS59"].ToString() == ViewState["CountingSubmitJS59"].ToString())
                {
                    int int_年度 = Int32.Parse(ddl_年度.SelectedValue.ToString());
                    string str_決算月 = ddl_決算月.SelectedValue.ToString();
                    decimal dec_売上 = 0;
                    decimal dec_営業損益 = 0;
                    decimal dec_経営損益 = 0;
                    decimal dec_当期損益 = 0;
                    int int_非常勤事務男 = 0;
                    int int_非常勤事務女 = 0;
                    if (txt_売上.Text != "")
                    {
                        dec_売上 = Decimal.Parse(splitInt32(txt_売上.Text));
                    }
                    if (txt_営業損益.Text != string.Empty)
                    {
                        dec_営業損益 = Decimal.Parse(splitInt32(txt_営業損益.Text));
                    }
                    if (txt_経営損益.Text != "")
                    {
                        dec_経営損益 = Decimal.Parse(splitInt32(txt_経営損益.Text));
                    }
                    if (txt_当期損益.Text != "")
                    {
                        dec_当期損益 = Decimal.Parse(splitInt32(txt_当期損益.Text));
                    }
                    int int_常勤事務男 = Int32.Parse(splitInt32(txt_常勤事務男.Text));
                    int int_常勤事務女 = Int32.Parse(splitInt32(txt_常勤事務女.Text));
                    int int_常勤現場男 = Int32.Parse(splitInt32(txt_常勤現場男.Text));
                    int int_常勤現場女 = Int32.Parse(splitInt32(txt_常勤現場女.Text));

                    if (txt_非常勤事務男数.Text != "")
                    {
                        int_非常勤事務男 = Int32.Parse(splitInt32(txt_非常勤事務男数.Text));
                    }
                    if (txt_非常勤事務女数.Text != "")
                    {
                        int_非常勤事務女 = Int32.Parse(splitInt32(txt_非常勤事務女数.Text));
                    }
                    // Mode update
                    if (Session["mode_frmJ_CompHistoryInput"].ToString() == "2")
                    {
                        
                        // If param difference session below will change
                        int int_ID = Int32.Parse(Session["frmJ_CompHistoryInput_ID"].ToString());
                        if (int_ID != 0)
                        {
                            int result = frmJ_CompHistoryInput_Update(int_年度, str_決算月, dec_売上, dec_営業損益, dec_経営損益, dec_当期損益, int_常勤事務男, int_常勤事務女, int_常勤現場男, int_常勤現場女, int_非常勤事務女, int_非常勤事務男, int_ID);
                            if (result != 0)
                            {
                                Session["CountingSubmitJS59"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                btn_登録.Text = "登録";
                                ClearTextPage();
                                LoadDatainGridView(Int32.Parse(Session["企業コード_2"].ToString()));
                                Session["frmJ_CompHistoryInput_ID"] = "0";
                                Session["frmJ_JointCompBasicInfoRef_Year"] = int_年度.ToString();
                                Session["IdCurrentUpdate_60"] = int_ID;
                            }
                        }
                        else
                        {
                            int int_企業ID = Convert.ToInt32(Session["企業コード_2"]);
                            int result = frmJ_CompHistoryInput_Insert(int_年度, str_決算月, dec_売上, dec_営業損益, dec_経営損益, dec_当期損益, int_常勤事務男, int_常勤事務女, int_常勤現場男, int_常勤現場女, int_非常勤事務女, int_非常勤事務男, int_企業ID);
                            if (result != 0)
                            {
                                btn_次.Enabled = true;
                                //Session["IdCurrentOut_60"] = _Id + "";//Lay ra dong vua moi insert
                                Session["CountingSubmitJS59"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                LoadDatainGridView(Convert.ToInt32(Session["企業コード_2"]));
                                DataTable dt = frmJ_CompHistoryInput_Select本社履歴With企業ID年度(int_企業ID, int_年度);
                                Session["IdCurrentOut_60"] = dt.Rows[0]["ID"].ToString();
                                ClearTextPage();
                                ddl_年度.Focus();
                            }
                        }
                        
                    }
                    else if (Session["mode_frmJ_CompHistoryInput"].ToString() == "1")  
                    {
                        // Mode insert
                        if (Session["frmJ_CompHistoryInput_ID"] != null && Session["frmJ_CompHistoryInput_ID"].ToString() != "")//Update of Insert
                        {

                            int int_ID = Int32.Parse(Session["frmJ_CompHistoryInput_ID"].ToString());
                            int result = frmJ_CompHistoryInput_Update(int_年度, str_決算月, dec_売上, dec_営業損益, dec_経営損益, dec_当期損益, int_常勤事務男, int_常勤事務女, int_常勤現場男, int_常勤現場女, int_非常勤事務女, int_非常勤事務男, int_ID);
                            if (result != 0)
                            {
                                btn_登録.Text = "登録";
                                Session["CountingSubmitJS59"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                LoadDatainGridView(Convert.ToInt32(Session["企業コード_2"]));
                                Session["frmJ_CompHistoryInput_ID"] = "0";
                                ClearTextPage();
                                Session["IdCurrentUpdate_60"] = int_ID;
                            }
                           
                        }
                        else//Insert of insert
                        {
                            int int_企業ID = Convert.ToInt32(Session["企業コード_2"]);
                            int result = frmJ_CompHistoryInput_Insert(int_年度, str_決算月, dec_売上, dec_営業損益, dec_経営損益, dec_当期損益, int_常勤事務男, int_常勤事務女, int_常勤現場男, int_常勤現場女, int_非常勤事務女, int_非常勤事務男, int_企業ID);
                            if (result != 0)
                            {
                                btn_次.Enabled = true;
                                //Session["IdCurrentOut_60"] = _Id + "";//Lay ra dong vua moi insert
                                Session["CountingSubmitJS59"] = Server.UrlEncode(System.DateTime.Now.ToString());
                                LoadDatainGridView(Convert.ToInt32(Session["企業コード_2"]));
                                ClearTextPage();
                                ddl_年度.Focus();
                                DataTable dt = frmJ_CompHistoryInput_Select本社履歴With企業ID年度(int_企業ID, int_年度);
                                Session["IdCurrentOut_60"] = dt.Rows[0]["ID"].ToString();
                            }
                            
                        }
                    }
                }
                else//Avoid insert twice when refesh page in IE
                { 
                    //Da submit roi khong cho submit lan nua khi Refesh
                    ClearTextPage();
                    LoadDatainGridView(Convert.ToInt32(Session["企業コード_2"]));
                }
            }

        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }

    }
    
    /// <summary>
    /// Load thong diep loi len cac control
    /// </summary>
    private void LoadErrorMessage()
    {
        RequiredFieldValidator1.ErrorMessage = GetError("ER00007");
        RequiredFieldValidator2.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator3.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator4.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator5.ErrorMessage =  GetError("ER00001");
        //RequiredFieldValidator6.ErrorMessage = "非常勤事務男数" + GetError("ER00001");
        //RequiredFieldValidator7.ErrorMessage = "非常勤事務女数" + GetError("ER00001");
        RequiredFieldValidator8.ErrorMessage =  GetError("ER00007");
        //CustomValidator1.ErrorMessage = GetError("ER00005");
        CustomValidator1.ErrorMessage = GetError("ER00002");
        CustomValidator2.ErrorMessage = GetError("ER00002");
        CustomValidator3.ErrorMessage = GetError("ER00002");

    }
    
    /// <summary>
    /// Lay ma loi tu CSDL
    /// </summary>
    /// <param name="p"></param>
    /// <returns></returns>
    private string GetError(string p)
    {
        Error er = new Error();
        er.ErrorID = p;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        return dt.Rows[0][2].ToString();
    }
   
    /// <summary>
    /// Xoa text
    /// </summary>
    private void ClearTextPage()
    {
        ddl_年度.Focus();
        ddl_年度.SelectedIndex = 0;
        ddl_決算月.SelectedIndex = 0;
        txt_売上.Text = "";
        txt_営業損益.Text = "";
        txt_経営損益.Text = "";
        txt_当期損益.Text = "";
        txt_常勤事務男.Text = "";
        txt_常勤事務女.Text = "";
        txt_常勤現場男.Text = "";
        txt_常勤現場女.Text = "";
        txt_非常勤事務男数.Text = "";
        txt_非常勤事務女数.Text = "";
    }
    /// <summary>
    /// ViewState["EmtyData"] = 2; exists data in Gridview
    /// ViewState["EmtyData"] = 1; not exists data in Gridview
    /// </summary>
    /// <summary>
    /// Load du lieu cho Gridview truong hop mode: Insert
    /// </summary>
    private void LoadDatainGridView(int 企業ID)
    {
        DataTable dt = _本社履歴Manager.frmJ_CompHistoryInput_Select本社履歴With企業ID(企業ID);
        if (dt.Rows.Count > 0)
        {
            grv.DataSource = dt;
            grv.DataBind();
            ViewState["EmtyData"] = "2";
        }
        else
        { 
            ViewState["EmtyData"] = "1"; 
            AppCode_Common.ShowEmtyGrid<本社履歴>(grv, 4, "データがありません。", ""); 
        }
    }
   

    protected void grv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        int index = e.NewPageIndex;
        ViewState["indexPage"] = index;
        grv.PageIndex = index;
        LoadDatainGridView(Convert.ToInt32(Session["企業コード_2"]));
    }
    
    protected void grv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onclick", "javascript:__doPostBack('ctl00$ContentPlaceHolder1$grv','Load$" + e.Row.RowIndex + "')");
        }
    }
    
    /// <summary>
    /// Hien thi dong dc chon tu gridview den cac control
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Load"))
        {

            if ((string)ViewState["EmtyData"].ToString() == "1")
            {
                AppCode_Common.ShowEmtyGrid<本社履歴>(grv, 4, "データがありません。", "");
                return;
            }

            int pagecurrent = Int32.Parse(ViewState["indexPage"].ToString());
            int index;
            if (pagecurrent == 0)
            {
                index = Int32.Parse(e.CommandArgument.ToString());
            }
            else
            {
                index = Convert.ToInt32(e.CommandArgument) + pagecurrent * 10;
            }
        
            DataTable dt = _本社履歴Manager.frmJ_CompHistoryInput_Select本社履歴With企業ID(Convert.ToInt32(Session["企業コード_2"]));
            
            string temp = dt.Rows[index]["年度"].ToString();
            if (temp != "")
            {
                ListItem lst = ddl_年度.Items.FindByValue(temp);
                ddl_年度.SelectedIndex = ddl_年度.Items.IndexOf(lst);
            }

            txt_売上.Text = dt.Rows[index]["売上"].ToString();
            txt_営業損益.Text = dt.Rows[index]["営業損益"].ToString();
            txt_経営損益.Text = dt.Rows[index]["経営損益"].ToString();
            txt_当期損益.Text = dt.Rows[index]["当期損益"].ToString();
            txt_常勤事務男.Text = dt.Rows[index]["常勤事務男"].ToString();
            txt_常勤事務女.Text = dt.Rows[index]["常勤事務女"].ToString();
            txt_常勤現場男.Text = dt.Rows[index]["常勤現場男"].ToString();
            txt_常勤現場女.Text = dt.Rows[index]["常勤現場女"].ToString();
            txt_非常勤事務男数.Text = dt.Rows[index]["非常勤事務男"].ToString();
            txt_非常勤事務女数.Text = dt.Rows[index]["非常勤現場女"].ToString();
            LoadDataDropDownList_決算月(temp.ToString());
            temp = dt.Rows[index]["決算月"].ToString();
           
            if (temp != "")
            {
                ListItem lst = ddl_決算月.Items.FindByValue(temp);
                ddl_決算月.SelectedIndex = ddl_決算月.Items.IndexOf(lst);
            }
            Session["frmJ_CompHistoryInput_ID"] = dt.Rows[index]["ID"].ToString();
            Session["IndexRecordJS60"] = index.ToString();
            Session["DataTableJS60"] = dt;
            btn_登録.Text = "更新";
            ddl_年度.Focus();
            
        }
    }

    protected void grv_PreRender(object sender, EventArgs e)
    {
        //Session["IdCurrentOut_60"]: dong vua moi insert
        try
        {
            if (Session["IdCurrentOut_60"] != null && Session["IdCurrentOut_60"].ToString() != "")
            {
                if (String.IsNullOrEmpty(Session["IdCurrentOut_60"].ToString()))
                {
                    return;
                }

                for (int i = 0; i < grv.Rows.Count; i++)
                {
                    string Id = grv.DataKeys[i].Value.ToString();
                    string str = (string)Session["IdCurrentOut_60"];
                    if (Id == str)
                    {
                        grv.Rows[i].CssClass = "insert";
                        Session["IdCurrentOut_60"] = "";
                        break;

                    }
                }
            }

            string IdCurrentUpdate_60 = Session["IdCurrentUpdate_60"] != null ? Session["IdCurrentUpdate_60"].ToString() : "";
            if (IdCurrentUpdate_60 != "")
            {
                for (int i = 0; i < grv.Rows.Count; i++)
                {
                    string Id = grv.DataKeys[i].Value.ToString();
                    string str = IdCurrentUpdate_60;
                    if (Id == str)
                    {
                        grv.Rows[i].CssClass = "update";
                        Session["IdCurrentUpdate_60"] = "";
                        break;
                    }
                }
            }
        }
        catch (Exception Exs) 
        {
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Load data for drowdownlist with condition
    /// </summary>
    protected void LoadDataDropDownList_年度()
    {
        if(Session["企業コード_2"]==null || Session["企業コード_2"].ToString()=="")
        {
            Response.Redirect("~/frmD_Login.aspx");
        }
        int int_企業ID = Int32.Parse(Session["企業コード_2"].ToString());
        //Get year establish from table 本社情報 with 企業ID
        DataTable dt = frmJ_CompHistoryInput_Get設立年月日_本社情報(int_企業ID);
        // Data not exists in table
        if (dt.Rows.Count == 0)
        {
            Response.Redirect("~/frmD_Login.aspx");
        }
        int int_YearMax = DateTime.Now.Year;//current year
        int int_YearMin = int_YearMax - 10;
        int int_YearStart = 0;
        if (Convert.ToInt32(dt.Rows[0]["Year"]) <= int_YearMin)
        {
            //int_YearStart = (int_YearMax + 1) - 10;
            int_YearStart = int_YearMax  - 10;
        }
        else
        {
            int_YearStart = Convert.ToInt32(dt.Rows[0]["Year"]);
        }
        for (int i = int_YearStart; i <= int_YearMax; i++)
        {
            ListItem lst = new ListItem(i.ToString(), i.ToString());
            ddl_年度.Items.Add(lst);
        }

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Load month with year establish
    /// </summary>
    /// <param name="str_Year"></param>
    protected void LoadDataDropDownList_決算月(string str_Year)
    {
        int int_企業ID = Int32.Parse(Session["企業コード_2"].ToString());
        DataTable dt = frmJ_CompHistoryInput_Get設立年月日_本社情報(int_企業ID);
        if (dt.Rows.Count == 0)
        {
            Response.Redirect("~/frmD_Login.aspx");
        }
        else
        {
            ddl_決算月.Items.Clear();
            int int_Month = 1;
            if (str_Year == dt.Rows[0]["Year"].ToString())
            {
                int_Month = Convert.ToInt32(dt.Rows[0]["Month"]);
            }
            for (int i = int_Month; i <= 12; i++)
            {
                ListItem lst = new ListItem(i.ToString() + "月", i.ToString());
                ddl_決算月.Items.Add(lst);
            }
            ListItem item = new ListItem("[選択]", "-1");
            item.Selected = true;
            ddl_決算月.Items.Insert(0, item);
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Button リセット
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_リセット_Click(object sender, EventArgs e)
    {
        if (Session["mode_frmJ_CompHistoryInput"].ToString() == "2" && Session["mode_frmJ_CompHistoryInput"] != null)
        {
            Response.Redirect("frmJ_CompHistoryInput.aspx?year=" + Session["frmJ_JointCompBasicInfoRef_Year"].ToString());
        }
        else
        {
            Session["frmJ_CompHistoryInput_ID"] = "0";
            ClearTextPage();
        }
       
    }

    /// <summary>
    /// Xoa day phay khoi so
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    protected string splitInt32(string value)
    {
        if (value == "" || value.Trim().Length < 0)
        {
            return "";
        }
        if (value.IndexOf(",") > -1)
        {
            string result = "";
            result = value.Replace(",","");
            return result;
        }
        else
        {
            return value;
        }
    }

    /// <summary>
    /// Coder: Ha Van Hoat
    /// Function: Format dinh dang tien
    /// Date: 20.02.2012
    /// </summary>
    /// <param name="src"></param>
    /// <returns></returns>
    protected string SplitMoney(object src)
    {
        if (src == null || src.ToString() == "")
        {
            return "";
        }
        string value = src.ToString();
        return value;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Get 設立年月日 from table 本社情報
    /// </summary>
    /// <param name="企業ID"></param>
    /// <returns></returns>
    public DataTable frmJ_CompHistoryInput_Get設立年月日_本社情報(int 企業ID)
    {
        return _本社情報Manager.frmJ_CompHistoryInput_Get設立年月日_本社情報(企業ID);
    }
    
    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Click dropdownlist 年度 load all control
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddl_年度_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_年度.SelectedValue.ToString() != "-1")
        {
            if (Session["企業コード_2"] == null || Session["企業コード_2"].ToString() == "")
            {
                Response.Redirect("~/frmD_Login.aspx");
            }
            int int_企業ID = Int32.Parse(Session["企業コード_2"].ToString());
            int int_年度 = Int32.Parse(ddl_年度.SelectedValue);
            DataTable dt = frmJ_CompHistoryInput_Select本社履歴With企業ID年度(int_企業ID, int_年度);
            if (dt.Rows.Count > 0)
            {
              
                txt_売上.Text = dt.Rows[0]["売上"].ToString();
                txt_営業損益.Text = dt.Rows[0]["営業損益"].ToString();
                txt_経営損益.Text = dt.Rows[0]["経営損益"].ToString();
                txt_当期損益.Text = dt.Rows[0]["当期損益"].ToString();

                txt_常勤事務男.Text = dt.Rows[0]["常勤事務男"].ToString();
                txt_常勤事務女.Text = dt.Rows[0]["常勤事務女"].ToString();
                txt_常勤現場男.Text = dt.Rows[0]["常勤現場男"].ToString();
                txt_常勤現場女.Text = dt.Rows[0]["常勤現場女"].ToString();
                txt_非常勤事務男数.Text = dt.Rows[0]["非常勤事務男"].ToString();
                txt_非常勤事務女数.Text = dt.Rows[0]["非常勤現場女"].ToString();
                Session["frmJ_CompHistoryInput_ID"] = dt.Rows[0]["ID"].ToString();
                string temp = dt.Rows[0]["決算月"].ToString();
                if (dt.Rows[0]["決算月"].ToString() != "")
                {
                    ListItem lst = ddl_決算月.Items.FindByValue(temp);
                    ddl_決算月.SelectedIndex = ddl_決算月.Items.IndexOf(lst);
                }
                btn_登録.Text = "更新";
                btn_登録.Focus();
            }
            else
            {
                ddl_決算月.Focus();
            }
            LoadDatainGridView(Convert.ToInt32(Session["企業コード_2"]));
            LoadDataDropDownList_決算月(int_年度.ToString());
        }
        else
        {
            ClearTextPage();
        }
        
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Get detail information table 本社履歴
    /// </summary>
    /// <param name="企業ID"></param>
    /// <param name="年度"></param>
    /// <returns></returns>
    public DataTable frmJ_CompHistoryInput_Select本社履歴With企業ID年度(int 企業ID, int 年度)
    {
        return _本社履歴Manager.frmJ_CompHistoryInput_Select本社履歴With企業ID年度(企業ID, 年度);
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Update table 本社履歴
    /// </summary>
    /// <param name="年度"></param>
    /// <param name="決算月"></param>
    /// <param name="売上"></param>
    /// <param name="営業損益"></param>
    /// <param name="経営損益"></param>
    /// <param name="当期損益"></param>
    /// <param name="常勤事務男"></param>
    /// <param name="常勤事務女"></param>
    /// <param name="常勤現場男"></param>
    /// <param name="常勤現場女"></param>
    /// <param name="非常勤現場女"></param>
    /// <param name="非常勤事務男"></param>
    /// <param name="ID"></param>
    /// <returns></returns>
    public int frmJ_CompHistoryInput_Update(int 年度, string 決算月, decimal 売上, decimal 営業損益, decimal 経営損益, decimal 当期損益, int 常勤事務男, int 常勤事務女, int 常勤現場男, int 常勤現場女, int 非常勤現場女, int 非常勤事務男, int ID)
    {
        return _本社履歴Manager.frmJ_CompHistoryInput_Update(年度, 決算月, 売上, 営業損益, 経営損益, 当期損益, 常勤事務男, 常勤事務女, 常勤現場男, 常勤現場女, 非常勤現場女, 非常勤事務男, ID);
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Insert data to table 本社履歴
    /// </summary>
    /// <param name="年度"></param>
    /// <param name="決算月"></param>
    /// <param name="売上"></param>
    /// <param name="営業損益"></param>
    /// <param name="経営損益"></param>
    /// <param name="当期損益"></param>
    /// <param name="常勤事務男"></param>
    /// <param name="常勤事務女"></param>
    /// <param name="常勤現場男"></param>
    /// <param name="常勤現場女"></param>
    /// <param name="非常勤現場女"></param>
    /// <param name="非常勤事務男"></param>
    /// <returns></returns>
    public int frmJ_CompHistoryInput_Insert(int 年度, string 決算月, decimal 売上, decimal 営業損益, decimal 経営損益, decimal 当期損益, int 常勤事務男, int 常勤事務女, int 常勤現場男, int 常勤現場女, int 非常勤現場女, int 非常勤事務男, int 企業ID)
    {
        return _本社履歴Manager.frmJ_CompHistoryInput_Insert(年度, 決算月, 売上, 営業損益, 経営損益, 当期損益, 常勤事務男, 常勤事務女, 常勤現場男, 常勤現場女, 非常勤現場女, 非常勤事務男, 企業ID);
    }
}
